package com.df.my_net_game.common.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;


/**
 * 定时任务配置
 * 注意定时任务的几种方式区别：timer-timertask,schedule,quartz
 */
@Slf4j
@Component
@EnableScheduling
public class ScheduleTaskConfig implements SchedulingConfigurer {

	@Override
	public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {

//		Trigger twelveHourTrigger = triggerContext -> {
//			// 0点开始 每6小时执行一次
//			CronTrigger cronTrigger = new CronTrigger("0 0 0/12 * * ? ");
//			return cronTrigger.nextExecution(triggerContext);
//		};
//		scheduledTaskRegistrar.addTriggerTask(() -> {
//		},twelveHourTrigger);
//
//
//		Trigger onlineLogTrigger = triggerContext -> {
//			// 每5分钟发一次在线人数 分别代表秒、分、小时、日、月、周和年
//			CronTrigger cronTrigger = new CronTrigger("0 5 * * * ? ");
//			return cronTrigger.nextExecution(triggerContext);
//		};
//
//
//		scheduledTaskRegistrar.addTriggerTask(() -> {
//
//		}, onlineLogTrigger);
	}
}
